from langchain.agents import initialize_agent
from langchain_openai import OpenAI
from typing import Dict, Any

async def langchain_text_executor(node_id: str, node_data: Dict[str, Any]) -> Dict[str, Any]:
    input_text = node_data.get("data", {}).get("input", "")
    model_name = node_data.get("data", {}).get("model", "openai-gpt-3.5")
    api_key = node_data.get("data", {}).get("api_key", "your-openai-key")  # 实际从 config.yaml 加载
    tools = node_data.get("data", {}).get("tools", [])

    # 初始化 LangChain Agent
    llm = OpenAI(api_key=api_key, model=model_name)
    agent = initialize_agent(tools=tools, llm=llm, agent_type="zero-shot-react-description")

    # 执行 Agent
    result = agent.run(input_text)
    return {"node_id": node_id, "output": result}